PATH (variable)

PATH is an environment variable on Unix-like operating systems, DOS, OS/2, and Microsoft Windows, specifying a set of directories where executable programs are located. In general, each executing process or user session has its own PATH setting.

Unix and Unix-like

On POSIX and Unix-like operating systems, the $PATH variable is specified as a list of one or more directory names separated by colon (:) characters.[1][2]

The /bin, /usr/bin, and /usr/local/bin directories are typically included in most users' path setting (although this varies from implementation to implementation). The current directory (.) is sometimes included as well, allowing programs residing in the current working directory to be executed directly. Superuser (root) accounts as a rule do not include it in the path, however, in order to prevent the accidental execution of scripts residing in the current directory. Executing such a program requires the deliberate use of a directory prefix (./) on the command name.

When a command name is specified by the user or an exec call is made from a program, the system searches the path, examining each directory from left to right in the list, looking for a filename that matches the command name. Once found, the program is executed as a child process of the command shell or program that issued the command.

DOS, OS/2, and Windows

On DOS, OS/2, and Windows operating systems, the %PATH% variable is specified as a list of one or more directory names separated by semicolon (;) characters.[3]

The Windows system directory (typically C:\WINDOWS\system32) is typically the first directory in the path, followed by many (but not all) of the directories for installed software packages. Many programs do not appear in the path as they are not designed to be executed from a command window, but rather from a Graphical User Interface.

When a command is entered in a command shell or a system call is made by a program to execute a program, the system first searches the current working directory and then searches the path, examining each directory from left to right, looking for an executable filename that matches the command name given. Executable programs have filename extensions of EXE or COM, and batch scripts have extensions of BAT or CMD. Other executable filename extensions can be registered with the system as well.

Once a matching executable file is found, the system spawns a new process in which to run it.

References